﻿using System;
using System.Net;
using System.Text;

namespace LiveNet.Silverlight
{
    public sealed class LiveMediaRequestCreator : IWebRequestCreator<LiveMediaAuthenticationDetails>
    {
        #region IWebRequestCreator Members

        public HttpWebRequest Create(Uri url, LiveMediaAuthenticationDetails authenticationDetails)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            byte[] userPass = Encoding.Default.GetBytes(authenticationDetails.AccountId + ":" + authenticationDetails.AccountKey);
            string basic = "Basic " + Convert.ToBase64String(userPass);
            request.Headers["Authorization"] = basic;

            return request;
        }

        #endregion
    }
}
